import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MetricsModule } from './modules/metrics/metrics.module';
import { DeploymentModule } from './modules/deployment/deployment.module';
import { ResourcesModule } from './modules/resources/resources.module';
import { ReportsModule } from './modules/reports/reports.module';
import { TrackingModule } from './modules/tracking/tracking.module';
import { TokenModule } from './modules/token/token.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        const dbConfig = {
          type: 'mysql' as const,
          host: configService.get<string>('DB_HOST'),
          port: configService.get<number>('DB_PORT'),
          username: configService.get<string>('DB_USER'),
          password: configService.get<string>('DB_PWD'),
          database: configService.get<string>('DB_DATABASE'),
          entities: [__dirname + '/**/*.entity{.ts,.js}'],
          synchronize: configService.get<boolean>('DB_SYNC'),
          logging: configService.get<boolean>('DB_LOGGING'),
        };
        
        console.log('Database connection config (excluding password):', {
          ...dbConfig,
          password: '******',
        });
        
        return dbConfig;
      },
    }),
    MetricsModule,
    DeploymentModule,
    ResourcesModule,
    ReportsModule,
    TrackingModule,
    TokenModule,
  ],
})
export class AppModule {} 